<?php
/**
 * Created by PhpStorm.
 * User: DELL
 * Date: 2021/3/2
 * Time: 11:03
 */
namespace App\Api\V1\Models;
use Illuminate\Database\Eloquent\Model;

class Goods extends Model{

    public $timestamps = false;
    //查询商品列表
    public function getGoodsList(){
        return $this->get()->toArray();
    }
    //商品添加
    public function addGoodsItem(){
        $data =[
            'goods_category_id'=>'1',
            'name'=>'小米',
            'short_name'=>'',
            'product_name'=>'',
            'goods_code'=>'CS79617330',
            'goods_spu'=>'',
            'goods_sku'=>'',
            'bar_code'=>'',
            'brand_id'=>'0',
            'store_qty'=>'100',
            'comment_sum'=>'0',
            'sales_sum'=>'0',
            'page_views'=>'0',
            'measure'=>'100',
            'measure_type'=>'0',
            'is_postage'=>'0',
            'market_price'=>'15',
            'shop_price'=>'11',
            'integral_type'=>'0',
            'give_integral'=>'0',
            'is_integral'=>'0',
            'least_sum'=>'0',
            'purchase_sum'=>'0',
            'keywords'=>'222',
            'description'=>'',
            'content'=>'安抚话术覅欧三',
            'attachment'=>'',//图片
            'video'=>'',
            'unit'=>'',
            'is_recommend'=>'0',
            'is_new'=>'0',
            'is_hot'=>'0',
            'goods_type_id'=>'1',
            'sort'=>'2',
            'status'=>'1',
            'is_delete'=>'0',
            'create_time'=>strtotime("now"),
            'update_time'=>strtotime("now"),
        ];
        $this->goods_category_id = $data['goods_category_id'];
        $this->name = $data['name'];
        $this->short_name = $data['short_name'];
        $this->product_name = $data['product_name'];
        $this->goods_code = $data['goods_code'];
        $this->goods_spu = $data['goods_spu'];
        $this->goods_sku = $data['goods_sku'];
        $this->bar_code = $data['bar_code'];
        $this->brand_id = $data['brand_id'];
        $this->store_qty = $data['store_qty'];
        $this->comment_sum = $data['comment_sum'];
        $this->sales_sum = $data['sales_sum'];
        $this->page_views = $data['page_views'];
        $this->measure = $data['measure'];
        $this->measure_type = $data['measure_type'];
        $this->is_postage = $data['is_postage'];
        $this->market_price = $data['market_price'];
        $this->shop_price = $data['shop_price'];
        $this->integral_type = $data['integral_type'];
        $this->give_integral = $data['give_integral'];
        $this->is_integral = $data['is_integral'];
        $this->least_sum = $data['least_sum'];
        $this->purchase_sum = $data['purchase_sum'];
        $this->keywords = $data['keywords'];
        $this->description = $data['description'];
        $this->content = $data['content'];
        $this->attachment = $data['attachment'];
        $this->video = $data['video'];
        $this->unit = $data['unit'];
        $this->is_recommend = $data['is_recommend'];
        $this->is_new = $data['is_new'];
        $this->is_hot = $data['is_hot'];
        $this->goods_type_id = $data['goods_type_id'];
        $this->sort = $data['sort'];
        $this->status = $data['status'];
        $this->is_delete = $data['is_delete'];
        $this->create_time = $data['create_time'];
        $this->update_time = $data['update_time'];
        if ($this->save()){
            return $this->toArray();
        }
        return false;
    }
    //修改商品信息
    public function setGoodsItem(){
        $data =[
            'goods_category_id'=>'1',
            'name'=>'华为',
            'short_name'=>'',
            'product_name'=>'',
            'goods_code'=>'CS79617330',
            'goods_spu'=>'',
            'goods_sku'=>'',
            'bar_code'=>'',
            'brand_id'=>'0',
            'store_qty'=>'100',
            'comment_sum'=>'0',
            'sales_sum'=>'0',
            'page_views'=>'0',
            'measure'=>'100',
            'measure_type'=>'0',
            'is_postage'=>'0',
            'market_price'=>'15',
            'shop_price'=>'11',
            'integral_type'=>'0',
            'give_integral'=>'0',
            'is_integral'=>'0',
            'least_sum'=>'0',
            'purchase_sum'=>'0',
            'keywords'=>'222',
            'description'=>'',
            'content'=>'安抚话术覅欧三',
            'attachment'=>'',//图片
            'video'=>'',
            'unit'=>'',
            'is_recommend'=>'0',
            'is_new'=>'0',
            'is_hot'=>'0',
            'goods_type_id'=>'1',
            'sort'=>'2',
            'status'=>'1',
            'is_delete'=>'0',
            'update_time'=>strtotime("now"),
        ];
        $res = Goods::where('goods_id',1)->update($data);
        if ($res){
            return $this->toArray();
        }
        return false;
    }
    //删除商品
    public function delGoodsItem(){
        $res = Goods::where('goods_id',5)->delete();
        if($res){
            return $this->toArray();
        }
        return false;
    }
}